package com.cxf.dao.impl;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.cxf.dao.db.AccountDao;
import com.cxf.entity.Pet;
import com.cxf.entity.PetOwner;
import com.cxf.entity.PetStore;
import com.cxf.method.DMethod;

public class AccountDaoImpl implements AccountDao {

	public int insertAccount(PetStore petStore, PetOwner petOwner, Pet pet) {
		int flag = 0;
		String str = "insert into account(deal_type,pet_id,seller_id,buyer_id,price,deal_time) values (?,?,?,?,?,?)";
		List<Object> list = new ArrayList<Object>();
		
		java.util.Date date = new Date(System.currentTimeMillis());
		java.sql.Date date2 =  new java.sql.Date(date.getTime());
		if (pet.getOwnerId()==null) {
			list.add(0);
			list.add(pet.getPetId());
			list.add(petStore.getStoreId());
			list.add(petOwner.getOwnerId());
			list.add(pet.getPrice());
			list.add(date2);
		} else {
			list.add(1);
			list.add(pet.getPetId());
			list.add(petOwner.getOwnerId());
			list.add(petStore.getStoreId());
			list.add(pet.getPrice());
			list.add(date2);
		}
		flag = DMethod.update(str, list);
		return flag;
	}

	
	public ResultSet findAccountByStoreId(int i) {
		String str = "select * from account where seller_id=?";
		List<Object> list = new ArrayList<Object>();
		list.add(i);
		ResultSet resultSet = DMethod.look(str, list);
		return resultSet;
	}

}
